<%@ page language="java" import="java.util.*" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="/context/mytags.jsp"%>
<!DOCTYPE html>
<html>
 <head>
  <title>添加活动借用申请</title>
  <t:base type="jquery,easyui,tools,DatePicker"></t:base>
  <script type="text/javascript">
  //编写自定义JS代码
  </script>
 </head>
 <body>
  <t:formvalid formid="formobj" dialog="true" layout="table" action="activityBorrowController.do?addApply" tiptype="3" >
		<input id="id" name="id" type="hidden" value=""> 
		<table style=" " cellpadding="0" cellspacing="1" class="formtable">
				<tr>
					<td align="right">
						<label class="Validform_label">
							设备品牌、型号、编号:
						</label>
					</td>
					<td class="value">
						${device.brand.brandName}、${device.model.modelName}、${device.deviceNo}
					</td>
				</tr>	 
				<tr>
					<td align="right">
						<label class="Validform_label">
							设备状态:
						</label>
					</td>
					<td class="value">
							<t:enumSelect field="stateValue" type="radio"
									  defaultVal="${com.mengtian_tech.device_mgr.entity.device.DeviceState.NORMAL}" 
									  hasLabel="false"  
									  enumClass="com.mengtian_tech.device_mgr.entity.device.DeviceState"
									  blackList="2,3"
									  title="状态">
							</t:enumSelect>     
							<span class="Validform_checktip"></span>
							<label class="Validform_label" style="display: none;">状态</label>
					</td>
				</tr>	 
			</table>
	</t:formvalid>
		
	<div style="text-align:center;margin-top:20px;">
		<button type="button" id="but_login"  onclick="openScanWindow()" class="btn-big">
                 	 归还
        </button>
 	</div>
 </body>
 <script>
 	 
 $(document).ready(function(){
	 $('input[name="stateValue"]')[0].checked='checked';
 });
 
 
 	function openScanWindow(){ 
 		var api = frameElement.api; 
 		 var addurl = 'deviceOutStockController.do?goScan';
 		  $.dialog({
 			  	id:'goScan',
 				content: 'url:'+addurl,
 				lock : true,
 				zIndex: 62, 
 				width:500,
 				height:280,
 				title:'扫描电子标签', 
 				opacity : 0.3,
 				cache:false,
 			    ok: function(){
 			    	iframe = this.iframe.contentWindow;
 			    	var result = iframe.getScanResult();
 			    	 
 			    	if(result.success){
 			    		var id = result.id;
 			    		if(id == '${device.id}'){
 			    			var val =  doReturn();
 			    			if(val) api.close();
 			    			return val;

 			    		}else{
 			    			alert('扫描设备与实际借用设备不匹配');
 			    			return false;
 			    		}
 			    	}else{
 			    		tip("请重新扫描设备");
 			    	}
 					
 			    },
 			    cancelVal: '关闭',
 			    cancel: true /*为true等价于function(){}*/,
 			    parent:api
 			});
 	  } 
 	  
 	  
 	  /**
 	  *  执行出库操作
 	  */
 	  function doReturn(){
 		  var  result = true;
 		  var state = 0; 
 		  state = $('input[name="stateValue"]:checked').val();
 		  
 		  
 		  $.ajax({
 			  url:'deviceReturnController.do?doReturn&id=${device.id}&state='+state,
 			  async:false,
 			  success:function(d){
 				  d = $.parseJSON(d);
 				  result = d.success; 
 				  if(result){
 					 alert(d.msg); 	
 				  }else{
 					 alert(d.msg);
 				  }
 	 			  
 			  }
 		  });
 		  
 		  return result;
 	  }
 	  
 </script>
 